﻿using System;
using System.IO;
using UnityEngine;
using UnityEngine.UI;

// Token: 0x020002B4 RID: 692
public class SaveLoadMode : MonoBehaviour
{
	// Token: 0x06001180 RID: 4480 RVA: 0x00071730 File Offset: 0x0006F930
	private void Start()
	{
		this.GC = UnityEngine.Object.FindObjectOfType<GameControl>();
		if (this.mode != SaveLoadMode.MODE.NONE)
		{
			this.Setup(this.mode);
		}
	}

	// Token: 0x06001181 RID: 4481 RVA: 0x00071754 File Offset: 0x0006F954
	public void Setup(SaveLoadMode.MODE mode)
	{
		this.mode = mode;
		this.titleBG.color = ((mode != SaveLoadMode.MODE.SAVE) ? this.uiColorLoad : this.uiColorSave);
		this.titleText.text = ((mode != SaveLoadMode.MODE.SAVE) ? "ロード" : "セーブ");
		this.exeText.text = this.titleText.text;
		ToggleButton[] toggleButtons = this.pageRoot.ToggleButtons;
		ColorBlock onColor = (mode != SaveLoadMode.MODE.SAVE) ? this.colorsLoadOn : this.colorsSaveOn;
		ColorBlock offColor = (mode != SaveLoadMode.MODE.SAVE) ? this.colorsLoadOff : this.colorsSaveOff;
		for (int i = 0; i < toggleButtons.Length; i++)
		{
			toggleButtons[i].SetColor(onColor, offColor);
		}
		this.DataListup();
		this.ChangePage();
	}

	// Token: 0x06001182 RID: 4482 RVA: 0x0007182C File Offset: 0x0006FA2C
	private void ChangePage()
	{
		int value = this.pageRoot.Value;
		ColorBlock onColor = (this.mode != SaveLoadMode.MODE.SAVE) ? this.colorsLoadOn : this.colorsSaveOn;
		ColorBlock offColor = (this.mode != SaveLoadMode.MODE.SAVE) ? this.colorsLoadOff : this.colorsSaveOff;
		ToggleButton[] componentsInChildren = this.mainRoot.GetComponentsInChildren<ToggleButton>();
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			componentsInChildren[i].SetColor(onColor, offColor);
			int num = value * 10 + i;
			SaveHeader saveHeader = this.datas[num];
			Text component = componentsInChildren[i].transform.Find("Text Name").GetComponent<Text>();
			Text component2 = componentsInChildren[i].transform.Find("Text No").GetComponent<Text>();
			Text component3 = componentsInChildren[i].transform.Find("Text Time").GetComponent<Text>();
			component2.text = "No:" + (num + 1).ToString("00");
			component.text = ((saveHeader == null) ? "データがありません" : saveHeader.comment);
			component3.text = ((saveHeader == null) ? string.Empty : saveHeader.time);
			bool interactable = true;
			if (this.mode == SaveLoadMode.MODE.LOAD)
			{
				interactable = (this.datas[num] != null);
			}
			componentsInChildren[i].Interactable = interactable;
		}
		this.mainRoot.Value = -1;
	}

	// Token: 0x06001183 RID: 4483 RVA: 0x000719AC File Offset: 0x0006FBAC
	private void Update()
	{
		int num = this.NowListNo();
		this.exeButton.interactable = (num != -1);
		this.delButton.interactable = (num != -1 && this.datas[num] != null);
	}

	// Token: 0x06001184 RID: 4484 RVA: 0x000719F8 File Offset: 0x0006FBF8
	private void DataListup()
	{
		for (int i = 0; i < 50; i++)
		{
			this.datas[i] = SaveHeader.LoadSaveHeader(SaveLoadMode.GameSavePath(i));
		}
	}

	// Token: 0x06001185 RID: 4485 RVA: 0x00071A2C File Offset: 0x0006FC2C
	public static string GameSavePath(int no)
	{
		return Directory.GetCurrentDirectory() + "/UserData/save/Game/" + (no + 1).ToString("00") + ".gsd";
	}

	// Token: 0x06001186 RID: 4486 RVA: 0x00071A60 File Offset: 0x0006FC60
	private void Save()
	{
		int num = this.NowListNo();
		string def = (this.datas[num] == null) ? string.Empty : this.datas[num].comment;
		this.GC.CreateModalInputStringUI(false, "コメントを入力してください", new Action<string>(this.SaveExe), null, true, def);
	}

	// Token: 0x06001187 RID: 4487 RVA: 0x00071ABC File Offset: 0x0006FCBC
	public void SaveOverWrite()
	{
		string text = "セーブデータ" + (this.NowListNo() + 1).ToString("00") + "を上書き保存しますか？";
		this.GC.CreateModalYesNoUI(text, new Action(this.Save), null);
	}

	// Token: 0x06001188 RID: 4488 RVA: 0x00071B08 File Offset: 0x0006FD08
	private void SaveExe(string comment)
	{
		int num = this.NowListNo();
		string path = SaveLoadMode.GameSavePath(num);
		GlobalData.PlayData.Save(path, comment);
		this.datas[num] = new SaveHeader(GlobalData.PlayData.Header);
		GlobalData.continueSaveNo = num;
		this.ChangePage();
	}

	// Token: 0x06001189 RID: 4489 RVA: 0x00071B54 File Offset: 0x0006FD54
	private void Load()
	{
		string path = SaveLoadMode.GameSavePath(this.NowListNo());
		GlobalData.PlayData.Load(path);
		this.GC.ChangeScene("SelectScene", "Load", 1f);
	}

	// Token: 0x0600118A RID: 4490 RVA: 0x00071B94 File Offset: 0x0006FD94
	private void DeleteExe()
	{
		int num = this.NowListNo();
		string path = SaveLoadMode.GameSavePath(num);
		File.Delete(path);
		this.datas[num] = null;
		if (GlobalData.continueSaveNo == num)
		{
			GlobalData.continueSaveNo = -1;
		}
		this.ChangePage();
	}

	// Token: 0x0600118B RID: 4491 RVA: 0x00071BD8 File Offset: 0x0006FDD8
	private int NowListNo()
	{
		int value = this.pageRoot.Value;
		int value2 = this.mainRoot.Value;
		if (value2 != -1)
		{
			return value * 10 + value2;
		}
		return -1;
	}

	// Token: 0x0600118C RID: 4492 RVA: 0x00071C0C File Offset: 0x0006FE0C
	public void Radio_ChangePage(int no)
	{
		SystemSE.Play(SystemSE.SE.CHOICE);
		this.ChangePage();
	}

	// Token: 0x0600118D RID: 4493 RVA: 0x00071C1C File Offset: 0x0006FE1C
	public void Button_Exe()
	{
		int num = this.NowListNo();
		if (num == -1)
		{
			return;
		}
		SystemSE.Play(SystemSE.SE.CHOICE);
		if (this.mode == SaveLoadMode.MODE.SAVE)
		{
			if (this.datas[num] == null)
			{
				this.Save();
			}
			else
			{
				this.SaveOverWrite();
			}
		}
		else if (this.mode == SaveLoadMode.MODE.LOAD)
		{
			string text = "セーブデータ" + (num + 1).ToString("00") + "を読込みますか？";
			this.GC.CreateModalYesNoUI(text, new Action(this.Load), null);
		}
	}

	// Token: 0x0600118E RID: 4494 RVA: 0x00071CB4 File Offset: 0x0006FEB4
	public void Button_Del()
	{
		SystemSE.Play(SystemSE.SE.CHOICE);
		string text = "セーブデータ" + (this.NowListNo() + 1).ToString("00") + "を削除しますか？";
		this.GC.CreateModalYesNoUI(text, new Action(this.DeleteExe), null);
	}

	// Token: 0x0600118F RID: 4495 RVA: 0x00071D08 File Offset: 0x0006FF08
	public void Button_Return()
	{
		SystemSE.Play(SystemSE.SE.CLOSE);
		base.gameObject.SetActive(false);
	}

	// Token: 0x06001190 RID: 4496 RVA: 0x00071D1C File Offset: 0x0006FF1C
	public void Radio_Main(int no)
	{
		SystemSE.Play(SystemSE.SE.CHOICE);
	}

	// Token: 0x04001349 RID: 4937
	[SerializeField]
	private SaveLoadMode.MODE mode;

	// Token: 0x0400134A RID: 4938
	[SerializeField]
	private Color uiColorSave;

	// Token: 0x0400134B RID: 4939
	[SerializeField]
	private Color uiColorLoad;

	// Token: 0x0400134C RID: 4940
	[SerializeField]
	private ColorBlock colorsSaveOn;

	// Token: 0x0400134D RID: 4941
	[SerializeField]
	private ColorBlock colorsSaveOff;

	// Token: 0x0400134E RID: 4942
	[SerializeField]
	private ColorBlock colorsLoadOn;

	// Token: 0x0400134F RID: 4943
	[SerializeField]
	private ColorBlock colorsLoadOff;

	// Token: 0x04001350 RID: 4944
	[SerializeField]
	private Image titleBG;

	// Token: 0x04001351 RID: 4945
	[SerializeField]
	private Text titleText;

	// Token: 0x04001352 RID: 4946
	[SerializeField]
	private Text exeText;

	// Token: 0x04001353 RID: 4947
	[SerializeField]
	private RadioButtonGroup mainRoot;

	// Token: 0x04001354 RID: 4948
	[SerializeField]
	private RadioButtonGroup pageRoot;

	// Token: 0x04001355 RID: 4949
	[SerializeField]
	private Button exeButton;

	// Token: 0x04001356 RID: 4950
	[SerializeField]
	private Button delButton;

	// Token: 0x04001357 RID: 4951
	private SaveHeader[] datas = new SaveHeader[50];

	// Token: 0x04001358 RID: 4952
	private GameControl GC;

	// Token: 0x020002B5 RID: 693
	public enum MODE
	{
		// Token: 0x0400135A RID: 4954
		NONE,
		// Token: 0x0400135B RID: 4955
		SAVE,
		// Token: 0x0400135C RID: 4956
		LOAD
	}

	// Token: 0x020002B6 RID: 694
	public enum UICOLOR_TYPE
	{
		// Token: 0x0400135E RID: 4958
		BASE,
		// Token: 0x0400135F RID: 4959
		HIGH,
		// Token: 0x04001360 RID: 4960
		PRESSED,
		// Token: 0x04001361 RID: 4961
		DISABLE,
		// Token: 0x04001362 RID: 4962
		NUM
	}
}
